package com.heng.syncUp;

import org.openjdk.jol.info.ClassLayout;

import java.util.concurrent.TimeUnit;
//锁消除
public class SynchronizedDemo4 {
    static Object object = new Object();

    public void m1(){
        //锁消除的问题，JIT会无视它，synchronized(o)，每次new出来的锁，不存在了，非正常的！
        Object o = new Object();
        synchronized (o){
            System.out.println("---hello LockClearUPDemo\t"+o.hashCode()+"\t"+object.hashCode());
        }
    }

    public static void main(String[] args) {
//        try {TimeUnit.SECONDS.sleep(5);}catch (InterruptedException e) {e.printStackTrace();}

        SynchronizedDemo4 synchronizedDemo4 = new SynchronizedDemo4();
        for(int i = 1; i<= 10; i++) {
            new Thread(()->{
                synchronizedDemo4.m1();
            },String.valueOf(i)).start();
        }

//        synchronized (o) {
//            System.out.println(ClassLayout.parseInstance(o).toPrintable());
//        }
    }
}
